<?php

namespace App\Http\Requests\Frontend\V10\Repay;

use Illuminate\Foundation\Http\FormRequest;

class RepayRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        switch($this->method()) {
            case 'GET': {
                if ($this->routeIs('repay.history')) {
                    //借款历史记录
                    return [];
                } else if ($this->routeIs('repay.index')) {
                    //当前次借款详情列表
                    return [
                        'summary_id' => 'required|integer|min:1|exists:repay_summaries,id'
                    ];
                }
            }
        }
        return [];
    }

    /**
     * 验证信息返回
     *
     * @return array
     */
    public function messages()
    {
        return [
            'summary_id.required' => '缺少summary_id',
            'summary_id.integer' => 'summary_id必须为整型',
            'summary_id.min' => 'summary_id最小值超出范围',
            'summary_id.exists' => 'summary_id不存在',
        ];
    }
}
